package com.booking.common.dto;

import com.booking.common.enums.BookingErrorCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @author Qikai.Lin
 * @date 2023/4/21
 */
@Data
public class ClientResp<T> implements Serializable {
    public static final String RESULT_CODE = "0000";
    public static final String RESULT_MSG = "success";
    public static final Boolean RESULT_SUCCESS = true;
    private String code;
    private String msg;
    private Boolean success;
    private T data;


    public ClientResp() {
    }

    public ClientResp(String code, String desc, Boolean success) {
        this.code = code;
        this.msg = desc;
        this.success = success;
        this.data = null;
    }

    public ClientResp(T resultData) {
        this.code = RESULT_CODE;
        this.msg = RESULT_MSG;
        this.success = RESULT_SUCCESS;
        this.data = resultData;
    }

    public static <K> ClientResp<K> success() {
        return new ClientResp<>(RESULT_CODE, RESULT_MSG, RESULT_SUCCESS);
    }
    public static <K> ClientResp<K> success(K data) {
        return new ClientResp<>(data);
    }

    public static <K> ClientResp<K> failure(String resultCode, String resultDesc) {
        return new ClientResp<>(resultCode, resultDesc, false);
    }

    public static <K> ClientResp<K> failure(BookingErrorCode errorCode) {
        return new ClientResp<>(errorCode.getCode(), errorCode.getMsg(), false);
    }


}
